package cn.edu.sgu.www.mhxysy.controller;

import cn.edu.sgu.www.mhxysy.consts.MimeType;
import cn.edu.sgu.www.mhxysy.entity.Area;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author heyunlin
 * @version 1.0
 */
@RestController
@RequestMapping(path = "/area", produces = MimeType.APPLICATION_JSON_CHARSET_UTF_8)
public class AreaController {

	private final AreaService areaService;

	@Autowired
	public AreaController(AreaService areaService) {
		this.areaService = areaService;
	}

	@RequestMapping(value = "/selectAll", method = RequestMethod.GET)
	public JsonResult<List<Area>> selectAll() {
		List<Area> list = areaService.selectAll();

		return JsonResult.success(null, list);
	}

	@RequestMapping(value = "/selectById", method = RequestMethod.GET)
	public JsonResult<Area> selectById(@RequestParam Integer id) {
		Area area = areaService.selectById(id);

		return JsonResult.success(null, area);
	}

}